package hbt;

import java.util.List;

import modelo.Comparativa;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import ViewObjects.ComparativaView;

public class HibernateComparativaDAO {

	private static HibernateComparativaDAO instancia = null;
	private static SessionFactory sf = null;

	public static HibernateComparativaDAO getInstancia() {
		if (instancia == null) {
			sf = HibernateUtil.getSessionFactory();
			instancia = new HibernateComparativaDAO();
		}
		return instancia;
	}

	public void grabarComparativa(Comparativa comp) {
		Session session = sf.openSession();
		session.beginTransaction();
		session.persist(comp);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}

	public List<ComparativaView> consCompPaisOrigen(String paisOrigen) {
		// TODO Auto-generated method stub
		Session session = sf.openSession();

		@SuppressWarnings("unchecked")
		List<ComparativaView> comparativa = session
				.createQuery("from Comparativa comp where  comp.paisorigen = ?")
				.setString(0, paisOrigen).list();

		session.close();
		return comparativa;
	}

	public List<ComparativaView> consCompMarca(String marca) {
		// TODO Auto-generated method stub
		Session session = sf.openSession();

		@SuppressWarnings("unchecked")
		List<ComparativaView> comparativa = session
				.createQuery("from Comparativa comp where  comp.marca = ?")
				.setString(0, marca).list();

		session.close();
		return comparativa;
	}

	public List<ComparativaView> consCompCodigoSFKyPaisOrigen(String codigoSFK,
			String paisOrigen) {
		// TODO Auto-generated method stub
		Session session = sf.openSession();

		@SuppressWarnings("unchecked")
		List<ComparativaView> comparativa = session
				.createQuery(
						"from Comparativa comp where  comp.codigoSFK = ? and comp.paisorigen = ?")
				.setString(0, codigoSFK).setString(1, paisOrigen).list();

		session.close();
		return comparativa;

	}

	public List<ComparativaView> consCompCodigoSFKyMarca(String codigoSFK,
			String marca) {
		// TODO Auto-generated method stub
		Session session = sf.openSession();

		@SuppressWarnings("unchecked")
		List<ComparativaView> comparativa = session
				.createQuery(
						"from Comparativa comp where  comp.codigoSFK = ? and comp.marca = ?")
				.setString(0, codigoSFK).setString(1, marca).list();

		session.close();
		return comparativa;

	}

	public List<ComparativaView> consCompCodigoSFK(String codigoSFK) {
		// TODO Auto-generated method stub
		Session session = sf.openSession();

		@SuppressWarnings("unchecked")
		List<ComparativaView> comparativa = session
				.createQuery("from Comparativa comp where  comp.codigoSFK = ?")
				.setString(0, codigoSFK).list();

		session.close();
		return comparativa;
	}

	public List<ComparativaView> consCompCodigoFabricanteyMarca(
			String codigoFabricante, String marca) {
		// TODO Auto-generated method stub
		Session session = sf.openSession();

		@SuppressWarnings("unchecked")
		List<ComparativaView> comparativa = session
				.createQuery(
						"from Comparativa comp where  comp.codigoFabricante = ? and marca = ?")
				.setString(0, codigoFabricante).setString(1, marca).list();

		session.close();
		return comparativa;

	}

	public List<ComparativaView> consCompCodigoFabricante(
			String codigoFabricante) {
		// TODO Auto-generated method stub
		Session session = sf.openSession();

		@SuppressWarnings("unchecked")
		List<ComparativaView> comparativa = session
				.createQuery(
						"from Comparativa comp where  comp.codigoFabricante = ?")
				.setString(0, codigoFabricante).list();

		session.close();
		return comparativa;
	}

	public List<ComparativaView> consCompCodigoFabricanteyPaisOrigen(
			String codigoFabricante, String paisOrigen) {
		// TODO Auto-generated method stub
		Session session = sf.openSession();

		@SuppressWarnings("unchecked")
		List<ComparativaView> comparativa = session
				.createQuery(
						"from Comparativa comp where  comp.codigoFabricante = ? and paisOrigen = ?")
				.setString(0, codigoFabricante).setString(1, paisOrigen).list();

		session.close();
		return comparativa;
	}

}
